package com.ruoyi.ly.controller;

import com.ruoyi.ly.domain.dto.MobileLinkAddDTO;
import com.ruoyi.ly.domain.dto.MobileLinkUpdateDTO;
import com.ruoyi.ly.domain.dto.PageMobileLinkDTO;
import com.ruoyi.ly.domain.vo.MobileLinkVO;
import com.ruoyi.ly.service.MobileLinkService;
import com.ruoyi.ly.utils.PageResult;
import com.ruoyi.ly.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/mobile/link")
@Api("跳转链接接口")
@Slf4j
public class MobileLinkController {

    @Autowired
    private MobileLinkService mobileLinkService;


    //  新增跳转链接信息
    @PostMapping("/add")
    @ApiOperation(value = "新增跳转链接信息")
    public Result<String> insert(@RequestBody MobileLinkAddDTO mobileLinkDTO){
        log.info("新增跳转链接信息");
        mobileLinkService.save(mobileLinkDTO);
        return Result.success();
    }

    //分页查询
    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public Result<PageResult> page(PageMobileLinkDTO pageMobileLinkDTO) {
        log.info("分页查询：{}", pageMobileLinkDTO);
        PageResult pageResult = mobileLinkService.pageQuery(pageMobileLinkDTO);
        return Result.success(pageResult);
    }

    //删除跳转链接
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除跳转链接")
    public Result delete(@PathVariable("id")Long id) {
        log.info("删除跳转链接：{}", id);
        mobileLinkService.delete(id);
        return Result.success();
    }

    //修改跳转链接
    @PutMapping("/update")
    @ApiOperation(value = "修改跳转链接")
    public Result update(@RequestBody MobileLinkUpdateDTO mobileLinkUpdateDto) {
        log.info("修改跳转链接：{}", mobileLinkUpdateDto);
        mobileLinkService.update(mobileLinkUpdateDto);
        return Result.success();
    }

    //根据跳转链接id查询跳转链接详情
    @GetMapping("/{id}")
    @ApiOperation(value = "根据跳转链接id查询跳转链接详情")
    public  Result<MobileLinkVO> selectById(@PathVariable Long id) {
        log.info("根据跳转链接id查询跳转链接详情：{}",id);
        MobileLinkVO mobileLinkVO = mobileLinkService.selectById(id);
        return Result.success(mobileLinkVO);
    }
}
